package com.tang.websocket.v1.handler;

import com.tang.websocket.v1.message.WebSocketMessage;
import com.tang.websocket.v1.session.WebSocketSession;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * @author Tang
 * @classname LoggingWebsocketHandlerDecorator
 * @description [  ]
 * @date 2022/11/28 22:27
 */
@Slf4j
public class LoggingWebsocketHandlerDecorator extends WebsocketHandlerDecorator {

    public LoggingWebsocketHandlerDecorator(WebSocketHandler webSocketHandler) {
        super(webSocketHandler);
    }

    @Override
    public void onOpen(WebSocketSession webSocketSession) {
        log.info("有新的连接进来了。。。");
        super.onOpen(webSocketSession);
    }

    @Override
    public void onMessage(WebSocketSession webSocketSession, WebSocketMessage<?> message) throws IOException {
        log.info("收到新的消息。。。");
        super.onMessage(webSocketSession, message);
    }

    @Override
    public void onClose(WebSocketSession webSocketSession) {
        log.info("连接正常关闭。。。");
        super.onClose(webSocketSession);
    }

    @Override
    public void onError(WebSocketSession webSocketSession, Throwable e) {
        log.info("连接异常关闭。。。");
        super.onError(webSocketSession, e);
    }
}
